/**
 * IObject is an abstract class used to build a complete
 * and organized object-oriented model in JavaScript.
 *
 * It provides very basic and standard tools for debugging
 * purposes and also defines standard variables.
 *
 * @param name	(optional) the IObject's instance name
 */
function	IObject(name)
{
    this._id			= IObject.ID++;	// unique ID
    this._name			= name;			// (non-unique) name
    this._type			= 'IObject';	// type;
    this._version		= 'x.xx.xx';	// development version number
    this._events		= new Object();	// events collection


//	alert('>>' + /(\w+)\(/.exec(this.constructor.toString())[1]);

    this.destroy		= function()
    {
        return (IObject.destroy(this));
    }

    this.getId			= function()
    {
        return (this._id);
    }

    this.getName		= function()
    {
        return (this._name);
    }

    this.getType		= function()
    {
        return (this._type);
    }

    this.getVersion		= function()
    {
        return (this._version);
    }

    this.getProperty    = function(propertyKey)
    {
        if (Base.isNotNull(propertyKey) && Base.exists(this[propertyKey]))
        {
           return (this[propertyKey]);
        }
        return (null);
    }

    this.setProperty     = function(propertyKey, propertyValue)
    {
       if (Base.isNotNull(propertyKey) && Base.exists(this[propertyKey]) &&
          Base.exists(propertyValue))
       {
           this[propertyKey] = propertyValue;
           return (true);
       }
       return (false);
    }

    this.toString		= function()
    {
        var	str		= new String();

        for (element in this)
        {
            if (typeof(this[element]) != 'function')
            {
                str += element + ':\t[' + this[element] + ']\n';
            }
        }
        return (str);
    }

    this.toHTML			= function()
    {
        var	html	= new String();

        html += '<DIV id="' + this.getId() + '" name="' + this.getName() + '">\n';
        html += ' <TABLE>\n';
        for (element in this)
        {
            if (typeof(this[element]) != 'function')
            {
                html += '  <TR id="' + this.getId() + '__' + element + '">\n';
                html += '   <TD name="key">\n';
                html += '    ' + element + '\n';
                html += '   </TD>\n';
                html += '   <TD name="value">\n';
                html += '    ' + this[element] + '\n';
                html += '   </TD>\n';
                html += '  </TR>\n';
            }
        }
        html += ' </TABLE>\n';
        html += '</DIV>\n';
        return (html);
    }

    IObject.instances[this.getId()] = this;
} // !IObject
IObject.ID			= 0;			//	Static ID counter
IObject.instances	= new Object();	//

IObject.clear	= function()
{
    if (IObject.instances)
    {
        for (i in IObject.instances)
        {
            var	instance	= IObject.getInstance(i);

            if (instance != null)
            {
                instance.destroy();
            }
            else
            {
                delete IObject.instances[i];
            }
        }
    }
}
IObject.destroy	= function(iobject)
{
    if (iobject)
    {
        if (iobject.getId &&
            IObject.instances && IObject.instances[iobject.getId()])
        {
            delete IObject.instances[iobject.getId()];
        }
        delete iobject;
        return (true);
    }
    return (false);
}
IObject.getInstance	= function(id)
{
    if (id && IObject.instances && IObject.instances[id])
    {
        return (IObject.instances[id]);
    }
    return (null);
}


if ((typeof(jssl) != 'undefined') && jssl && (jssl != null))
{
    if ((typeof(jssl) != 'undefined') && jssl.lang)
    {
        jssl.lang.IObject = IObject;
    }
    else
    {
        jssl.lang	=
        {
            IObject	: IObject
        };
    }
}
else
{
    jssl	=
    {
        lang	:
        {
            IObject	: IObject
        }
    };
}
